<template>
    <div>
        <div class="crumbs"> 
            <div class="container">
                 <div class="lu hnk"></div><div class="hnk jgxx">产品信息</div>
                 <div class="jgcontainer">
                    <!-- <div class="hnk con"> -->
                        <el-form ref="form" :model="form" label-width="130px">
                        <el-row :gutter="20" style="margin-top:20px;">
                            <el-col :span="10" style="margin-left:50px;">
                                <el-form-item label="选择产品">
                                    <el-select v-model="added.appId"  style="width:300px;" >
                                        <el-option v-for="(item,index) in fulist" :key="index" :label="item.name" :value="item.id"></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="产品图标">
                                    <el-upload
                                        class="upload-poster"                          
                                            action="https://jsonplaceholder.typicode.com/posts/"
                                            :show-file-list="false"
                                            :on-change="imgPreview"
                                            :auto-upload="false">
                                            <img v-if="headImg" :src="headImg" class="avatar">
                                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="产品名称" >
                                    <el-input class="handle-input" style="width:300px;" placeholder="不得超过6个字" v-model="added.name"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </div>
            <el-button type="success" style="margin-left:500px; margin-top:50px;" @click ="save">保存</el-button>
        </div>
    </div>
</template>

<script>
    import {control_list,control_save} from "@/request/api"
    export default {
        data(){
            return{
                added:{
                    appId:'',
                    name:'',
                    iconImg:'',
                    files:''
                },
                fulist:'',
                imageUrl:'',
                setup:"",
                form: {},
                headImg:''
            }
        },
        mounted(){
            this.getsystemsetupt()//获取系统设置
        },
        methods: {
            getsystemsetupt(){
                control_list("").then((res)=>{
                    this.fulist = res.data
                })
            },
            save(){
                let data = this.added
                let formdata = new FormData
                for(var a in this.added){
                    if(this.added[a] == null || this.added[a] == "null"){
                        this.added[a] = ""
                        formdata.append(a,'') 
                    }else{
                        formdata.append(a,this.added[a])
                    }
                }
                control_save(formdata).then((res)=>{
                    this.$notify({
                        title: '提示',
                        message: '保存成功',
                        type: 'success'
                    });
                    this.$router.push({
                        path:'/productManagement'
                    })
                })
            },
            imgPreview(file,fileList) {
                this.headImg =  URL.createObjectURL(file.raw);
                let fileName = file.name;
                let regex = /(.jpg|.gif|.png|.jpeg)$/;
                if (regex.test(fileName.toLowerCase())) {
                    this.added.files = file.raw
                    this.added.iconImg = file.name
                } else {
                    this.$message.error('请选择图片文件');
                }
                
            },
            // 判断输入框只能为正整数
            // Blurtext(e){
            //     let boolean = new RegExp("^[1-9][0-9]*$").test(e.target.value)
            //     if(!boolean){
            //         this.$message.warning("请输入正整数")
            //         e.target.value=""
            //     }
            // },
        }
       
    }

</script>

<style scoped>
.l{
    margin-left:25px;
}
.tables{
    width:90%;
    margin:0 auto;
    height:100px;
    
    position: relative;
    border:1px solid #666666;
}
.table-left{
    width:25%;
    text-align: center;
    position: absolute;
    line-height:100px;
    border-right:1px solid #666666;
    background: #d7d7d7;;
}
.table-right{
    padding:20px;
    width:73%;
    height:100px;
    /* margin-top:-100px; */
    /* float: left; */
    margin-left:260px;
    z-index:333;
}
.in{
    display: inline-block;
}
    .crumbs{
        width:95%;
        margin:0 auto;
        margin-top: 30px;
        background: #ffffff;
    }
    .container{
        padding:10px;
    }
    .lu{
        width: 8px;
        height: 16px;
        background: greenyellow;
    }
    .hnk{
        display:inline-block;
    }
    .jgxx{
        margin-left:10px ;
        font-weight:600;
        font-size: 15px;
    }
    .jgcontainer{
        font-weight: 400;
    }
    .con{
        width:40%;
        padding: 20px;
        font-size: 14px;
        margin-left: 20px;
    }
    .handle-input {
        width: 200px;
        display: inline-block;
        /* margin-left: 30px; */
    }
    .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    width: 100px;
    height: 100px;
    display: block;
  }
  
  
</style>
